#include "stdafx.h"
#include "SoundEffect2D.h"
#include <XAudio2.h>
#include "AudioManager.h"
/*static*/ const float SoundEffect2D::sampleSize = 44100.f;

SoundEffect2D::~SoundEffect2D(void)
{
	AudioManager* pAudio = AudioManager::GetInstance();
	for (unsigned int i = 0; i < pAudio->activeElements.size(); i++)
	{
		if (pAudio->activeElements[i] == this)
		{
			pAudio->activeElements.erase(pAudio->activeElements.begin() + i);
			break;
		}
	}

	sound->release();
}

SoundEffect2D::SoundEffect2D(void)
{
	AudioManager::GetInstance()->activeElements.push_back(this);
}

void SoundEffect2D::setIsLooped(bool value)
{
	FMOD_MODE mode;
	sound->getMode(&mode);
	if (value)
		mode |= FMOD_LOOP_NORMAL;
	else
		mode &= ~FMOD_LOOP_NORMAL;
	sound->setMode(mode);
}

/*virtual*/ void SoundEffect2D::Update(void) /*override*/
{
	if (channel)
	{
		channel->setVolume(volume);
	}
}